﻿<Window x:Class="LogicCircuit.DialogSensor"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:lc="clr-namespace:LogicCircuit"
	xmlns:properties="clr-namespace:LogicCircuit.Properties"
	WindowStartupLocation="CenterOwner"
	Title="{x:Static properties:Resources.NameSensor}"
	Style="{StaticResource DialogWindow}"
	MinHeight="320"
	FocusManager.FocusedElement="{Binding ElementName=sensorType}"
>
	<Window.Resources>
		<lc:EnumToVisibilityConvertor x:Key="EnumToVisibilityConvertor"/>

		<ControlTemplate x:Key="validationTemplate">
			<StackPanel Orientation="Horizontal">
				<TextBlock Foreground="Red" FontSize="20">!</TextBlock>
				<Border BorderBrush="Red" BorderThickness="1">
					<AdornedElementPlaceholder/>
				</Border>
			</StackPanel>
		</ControlTemplate>
	</Window.Resources>

	<lc:AutoGrid Margin="3">
		<Label Content="{x:Static properties:Resources.TitleSensorType}"/>
		<lc:AutoWidthComboBox x:Name="sensorType"
			ToolTip="{x:Static properties:Resources.ToolTipSensorType}"
			ItemsSource="{Binding Path=SensorTypes}"
			SelectedItem="{Binding Path=SelectedSensorType, ValidatesOnDataErrors=True}"
		/>

		<Label Content="{x:Static properties:Resources.TitleBitWidth}"/>
		<ComboBox Name="bitWidth" ToolTip="{x:Static properties:Resources.ToolTipSensorBitWidth}" MinWidth="{Binding ElementName=side, Path=ActualWidth}" HorizontalAlignment="Left"/>

		<Label Content="{x:Static properties:Resources.TitlePinSide}"/>
		<lc:AutoWidthComboBox x:Name="side" ToolTip="{x:Static properties:Resources.ToolTipDevicePinSide}"/>

		<Label Content="{x:Static properties:Resources.TitleNotation}"/>
		<TextBox Name="notation" MaxLength="8"/>

		<!-- Variable controls start here -->

		<Grid Height="0"> <!-- Make sure all labels allocating their space -->
			<Label Content="{x:Static properties:Resources.TitleSeries}" IsEnabled="False"/>
			<Label Content="{x:Static properties:Resources.TitleSensorRandomMin}" IsEnabled="False"/>
			<Label Content="{x:Static properties:Resources.TitleSensorRandomMax}" IsEnabled="False"/>
			<Label Content="{x:Static properties:Resources.TitleSensorManualInitialValue}" IsEnabled="False"/>
		</Grid>
		<Grid Height="0"/>

		<!-- Series -->

		<Label Content="{x:Static properties:Resources.TitleSeries}"
			Visibility="{Binding ElementName=sensorType, Path=SelectedItem.Value, Converter={StaticResource EnumToVisibilityConvertor}, ConverterParameter={x:Static lc:SensorType.Series}}"
		/>
		<TextBox Name="data"
			Visibility="{Binding ElementName=sensorType, Path=SelectedItem.Value, Converter={StaticResource EnumToVisibilityConvertor}, ConverterParameter={x:Static lc:SensorType.Series}}"
			Text="{Binding Path=SeriesData, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
			Validation.ErrorTemplate="{StaticResource validationTemplate}"
			ToolTip="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent, FallbackValue={x:Static properties:Resources.ToolTipSeriesData}}"
		/>

		<CheckBox Grid.Column="1" Content="{x:Static properties:Resources.TitleLoopSeries}"
			Visibility="{Binding ElementName=sensorType, Path=SelectedItem.Value, Converter={StaticResource EnumToVisibilityConvertor}, ConverterParameter={x:Static lc:SensorType.Series}}"
			IsChecked="{Binding Path=IsLoop}"
		/>

		<!-- Random -->

		<Label Content="{x:Static properties:Resources.TitleSensorRandomMin}"
			Visibility="{Binding ElementName=sensorType, Path=SelectedItem.Value, Converter={StaticResource EnumToVisibilityConvertor}, ConverterParameter={x:Static lc:SensorType.Random}}"
		/>
		<TextBox Name="minTicks"
			Visibility="{Binding ElementName=sensorType, Path=SelectedItem.Value, Converter={StaticResource EnumToVisibilityConvertor}, ConverterParameter={x:Static lc:SensorType.Random}}"
			Text="{Binding Path=RandomMin, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
			Validation.ErrorTemplate="{StaticResource validationTemplate}"
			ToolTip="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent, FallbackValue={x:Static properties:Resources.ToolTipSensorRandomMin}}"
		/>

		<Label Content="{x:Static properties:Resources.TitleSensorRandomMax}"
			Visibility="{Binding ElementName=sensorType, Path=SelectedItem.Value, Converter={StaticResource EnumToVisibilityConvertor}, ConverterParameter={x:Static lc:SensorType.Random}}"
		/>
		<TextBox Name="maxTicks"
			Visibility="{Binding ElementName=sensorType, Path=SelectedItem.Value, Converter={StaticResource EnumToVisibilityConvertor}, ConverterParameter={x:Static lc:SensorType.Random}}"
			Text="{Binding Path=RandomMax, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
			Validation.ErrorTemplate="{StaticResource validationTemplate}"
			ToolTip="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent, FallbackValue={x:Static properties:Resources.ToolTipSensorRandomMax}}"
		/>

		<!-- Manual -->

		<Label Content="{x:Static properties:Resources.TitleSensorManualInitialValue}"
			Visibility="{Binding ElementName=sensorType, Path=SelectedItem.Value, Converter={StaticResource EnumToVisibilityConvertor}, ConverterParameter={x:Static lc:SensorType.Manual}}"
		/>
		<TextBox Name="manualValue"
			Visibility="{Binding ElementName=sensorType, Path=SelectedItem.Value, Converter={StaticResource EnumToVisibilityConvertor}, ConverterParameter={x:Static lc:SensorType.Manual}}"
			Text="{Binding Path=ManualInitialValue, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
			Validation.ErrorTemplate="{StaticResource validationTemplate}"
			ToolTip="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent, FallbackValue={x:Static properties:Resources.ToolTipSensorManualInitialValue}}"
		/>

		<!-- End of variable controls -->

		<Label Content="{x:Static properties:Resources.TitleDescription}"/>
		<TextBox Name="note" AcceptsReturn="True"/>

		<StackPanel Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom">
			<Button Name="buttonOk" Content="{x:Static properties:Resources.TitleOK}" IsDefault="True" Click="ButtonOkClick"/>
			<Button Content="{x:Static properties:Resources.TitleCancel}" IsCancel="True"/>
		</StackPanel>
	</lc:AutoGrid>
</Window>
